﻿using System;
using System.Linq;
using System.Text.RegularExpressions;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using YJKSparseBreadth.Properties;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseBreadth.ModelLayer
{
	public class HostInRoomPacker_EvacuationWidth : BaseHostInRoomPacker
	{
		internal bool IfIsStair
		{
			get
			{
				return this.m_bIfIsStair;
			}
			private set
			{
				this.m_bIfIsStair = value;
			}
		}

		internal bool IfIsChair
		{
			get
			{
				return this.m_bIfIsChair;
			}
			private set
			{
				this.m_bIfIsChair = value;
			}
		}

		public bool IfGetStairWidthSucess
		{
			get
			{
				return this.m_bIfGetStairWidthSucess;
			}
			private set
			{
				this.m_bIfGetStairWidthSucess = value;
			}
		}

		public double StairsWidth
		{
			get
			{
				return this.m_dStairsWidth;
			}
			private set
			{
				this.m_dStairsWidth = value;
			}
		}

		public HostInRoomPacker_EvacuationWidth(Element inputElement, RevitLinkInstance useRevitLinkInstance = null, object[] otherValues = null) : base(inputElement, useRevitLinkInstance, otherValues)
		{
			if (inputElement != null && inputElement is Stairs)
			{
				this.IfIsStair = true;
				this.IfGetStairWidthSucess = this.TryGetStairWidth(out this.m_dStairsWidth);
				if (this.IfGetStairWidthSucess)
				{
					this.StairsWidth = AssistFunc.feetToMM(this.StairsWidth);
					this.StairsWidth /= 1000.0;
					return;
				}
			}
            else if (inputElement.Category.Id.IntegerValue == (int)(BuiltInCategory)Enum.Parse(typeof(BuiltInCategory), Resources.Str_FurnitureCategory) && inputElement != null && inputElement is FamilyInstance)
			{
				Family family = (inputElement as FamilyInstance).Symbol.Family;
				foreach (string pattern in Resources.Strs_KeyNamesOfChairs.Split(new char[]
				{
					','
				}).ToList<string>())
				{
					if (Regex.IsMatch(family.Name, pattern))
					{
						this.IfIsChair = true;
						break;
					}
				}
			}
		}

		private bool TryGetStairWidth(out double width)
		{
			width = 0.0;
			if (base.ThisElement == null || !(base.ThisElement is Stairs))
			{
				return false;
			}
			Stairs stairs = base.ThisElement as Stairs;
			StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
			if (stairsType == null)
			{
				return false;
			}
			Parameter parameter = stairsType.get_Parameter((BuiltInParameter)Enum.Parse(typeof(BuiltInParameter), Resources.Str_StairsWidthParam));
			if (parameter == null || (int)parameter.StorageType != 2)
			{
				return false;
			}
			width = parameter.AsDouble();
			return true;
		}

		private bool m_bIfIsStair;

		private bool m_bIfGetStairWidthSucess;

		private double m_dStairsWidth;

		private bool m_bIfIsChair;
	}
}
